package tree;


import lombok.extern.slf4j.Slf4j;

import java.util.*;

//Definition for a binary tree node.平衡二叉树
@Slf4j

public class IsBalanced {

    public boolean isBalanced(TreeNode root) {
        if(root==null){
            return true;
        }
        int leftHeight = root.leftHeight();
        int rightHeight = root.rightHeight();

        System.out.println("left="+leftHeight+",right="+rightHeight);

        return Math.abs(leftHeight-rightHeight)<=1&&isBalanced(root.left)&&isBalanced(root.right);



    }


    public static void main(String[] args){
        Integer[] nums={1,2,2,3,null,null,3,4,null,null,4};
        // Integer[] nums2={1};
        TreeNode treeNode = TreeNode.constructTree(nums);
        treeNode.printTree(treeNode);


        System.out.println(new IsBalanced().isBalanced(treeNode));


    }





}